package edu.taru.shop.listenter;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Application Lifecycle Listener implementation class OnlineStatisListenter
 *
 */
@WebListener
public class OnlineStatisListenter implements HttpSessionListener {
	int i=0;

    public void sessionCreated(HttpSessionEvent event)  { 
    	ServletContext application=event.getSession().getServletContext();
        synchronized (this) {
			i++;
			application.setAttribute("online", i);
		}
       
    }
  

    public void sessionDestroyed(HttpSessionEvent event)  { 
    	ServletContext application=event.getSession().getServletContext();
        synchronized (this) {
			i--;
			application.setAttribute("online", i);
		}
    }
	
}
